您的当前位置:首页 >探索 >短视频自动刷软件的开发:利用 android adb 命令模拟滑动 正文

短视频自动刷软件的开发:利用 android adb 命令模拟滑动

时间:2024-09-24 01:20:17 来源:网络整理编辑:探索

核心提示

近三年短视频出现了井喷式的发展快手怎么买双击,我们熟知常见的有抖音、快手、微视、火山小视频等,看短视频早已成了年青人的习惯快手怎么买双击,每晚课余的时间才会掏出手机刷刷刷,打发无趣的时间。虽然,抖音和 刷快手业粉丝

近三年短视频出现了井喷式的短视动刷的开动发展快手怎么买双击,我们熟知常见的频自有抖音、快手、软件刷快手业粉丝微视、发利火山小视频等,令模看短视频早已成了年青人的拟滑习惯快手怎么买双击,每晚课余的短视动刷的开动时间才会掏出手机刷刷刷,打发无趣的频自时间。

虽然,软件抖音和快手都推出了急速版,发利刷快手业粉丝在娱乐的令模同时还可以刷视频挣钱了,不过纯属娱乐,拟滑三天也没多少钱。短视动刷的开动

而且我们作为一个测试人员,频自有没有办法让视频手动刷上去呢。软件方式是有的,明天我们就来开发一个能手动刷短视频的软件。假如我们学会了,可以用到其他的一些能挣钱的应用上。

首先我们能想到的是开发手动化脚本,使用androidadb命令模拟滑动,命令为adbshellinputswipe,之后设置一个循环在等待固定的时间就滑动一次就行了,使用windows的批处理或则使用python开发一个脚本就行了。并且缺点特别命令,须要仍然开着笔记本,不能随时随地的刷,没有意义。

另一种方式可能想到是开发一个android的app应用,之后在应用中使用Android的Runtime方式调用adb滑动命令,如Runtime.getRuntime().exec(“inputswipe”),实际等你试了也不会成功,由于在应用中想要调用adb命令须要root权限,我们自己使用的普通手机都使用不上去的。

还有第三种方式就是android的辅助服务AccessibilityService。辅助服务的设计本意提供给难以和界面进行交互的残障用户来协助帮助她们进行一些用户操作,例如点击,返回,长按,获取屏幕信息等能力。后来被开发者另辟蹊径,用于一些插件开发,做一些窃听第三方应用的插件。

我们不会将辅助服务AccessibilityService怎样使用,也不会将如何打开应用的时侯引导用户开辅助服务,这种网上都可以搜到,只须要移植到过来即可。下边我们来讲在辅助服务中若果实现滑动、双击点赞、跳过广告等设计。

首先是关于滑动实现,主要使用的是AccessibilityService在android7.0上新增的dispatchGesture和GestureDescription类。关于两个类介绍如下,网上也有。

首先是dispatchGesture方式的解释:

boolean dispatchGesture (GestureDescription gesture, AccessibilityService.GestureResultCallback callback, Handler handler)

这个方式有三个参数:

参数GestureDescription:翻译过来就是手势的描述,假如要实现模拟,首先要描述你的腰模拟的手势;

参数GestureResultCallback:翻译过来就是手势的反弹,手势模拟执行之后反弹结果;

参数handler:大部份情况我们不用的话传空就可以了。

通常我们关注GestureDescription这个参数就够了,下面重点介绍一下这个参数:

建立一个手势描述的关键代码:

GestureDescription.StrokeDescription(Path path, long startTime, long duration);例如:GestureDescription.Builder builder = GestureDescription.Builder();GestureDescription gestureDescription = builder.addStroke(GestureDescription.StrokeDescription(path, 100, 400)).build();

参数介绍如下:

参数path:笔划路径,也就是滑动的路径,可以通过path.moveTo和path.lineTo实现;

参数startTime:时间(以微秒为单位),从手势开始到开始笔画的时间,非正数;

参数duration:笔画经过路径的持续时间(以微秒为单位),非正数;

介绍了前面的基础知识,我们就来看下滑动的代码须要怎样开发,见下边:

private void mockSwipe(){ final Path path = new Path();path.moveTo(X, Y); //滑动的起始位置,例如屏幕的中心点X、Ypath.lineTo(X, 0); //需要滑动的位置,如从中心点滑到屏幕的顶部GestureDescription.Builder builder = new GestureDescription.Builder();GestureDescription gestureDescription = builder.addStroke(new GestureDescription.StrokeDescription(path, 100, 400)).build(); //移动到中心点,100ms后开始滑动,滑动的时间持续400ms,可以调整dispatchGesture(gestureDescription, new GestureResultCallback() { @Override//如果滑动成功,会回调如下函数,可以在下面记录是否滑动成功,滑动成功或失败都要关闭该路径笔画public void onCompleted(GestureDescription gestureDescription) { super.onCompleted(gestureDescription);Log.d(TAG, "swipe  success.");path.close();}@Overridepublic void onCancelled(GestureDescription gestureDescription) { super.onCancelled(gestureDescription);Log.d(TAG, " swipe  fail.");path.close();}}, null); //handler为空即可 }

那滑动实现了,双击点赞是怎样实现的呢,其实你想到了,是的就是通过构造path实现,只须要将起始点和终点设置一样就可以了,而且不是设置lineTo和moveTo的座标一样就行,双击的实现方法如下:

private void mockDoubleClick(){ final Path path = new Path();path.moveTo((int)(X/2), (int)(Y/2));  //X和Y是需要双击的按钮坐标GestureDescription.Builder builder = new GestureDescription.Builder();GestureDescription gestureDescription = builder.addStroke(     new GestureDescription.StrokeDescription(path, 0, 100)).build();dispatchGesture(gestureDescription, new GestureResultCallback() { @Overridepublic void onCompleted(GestureDescription gestureDescription) { super.onCompleted(gestureDescription);Path path2 = new Path();            path2.moveTo((int)(X/2), (int)(Y/2));            //以下代码是完成第二个手势操作GestureDescription.Builder builder2 = new GestureDescription.Builder();GestureDescription gestureDescription2 = builder2.addStroke(            new GestureDescription.StrokeDescription(path2, 0, 100)).build();AccessibilityServiceTest.this.dispatchGesture(gestureDescription2, null, null);Log.d(TAG, "double click finish.");path.close();path2.close();            }            @Overridepublic void onCancelled(GestureDescription gestureDescription) { super.onCancelled(gestureDescription);Log.d(TAG, "scroll cancell.");}}, null);    }

至于查找控件,使用辅助服务AccessibilityService的AccessibilityNodeInfo和findAccessibilityNodeInfosByText即可,具体的操作如下:

rootInfo =AccessibilityServiceTest.this.getRootInActiveWindow();List listInfo = rootInfo.findAccessibilityNodeInfosByText("查找文本");

备注:关于app的其他开发方面没有提到,如假如添加辅助服务以及说明,请看原文中的AndroidManifest.xml和simulatekey.xml(辅助服务的设置)文件。